package pacman;

public class GhostRunner implements Runnable {
	Ghost g;

	public GhostRunner(Ghost g) {
		this.g = g;
	}

	public void run() {
		// Wacht totdat er genoeg joins
		while (g.getGame().stayInJoinPhase()){
			System.out.println("" + g.getName() + " wacht op joins of NAMEs! nu al "+ g.getGame().getNumberOfJoins());
			try {
				Thread.sleep(30);
			} catch (InterruptedException e) {
			}
		}
		System.out.println("Join phase gedaan voor " + g.getName());
		try {
			g.sendNAME();
			while (!g.getGame().isInitialized()) {
				Thread.sleep(20);
				System.out.println("" + g.getName() + " wacht op names!");
			}
			System.out.println("" + g.getName() + "begint!");
			System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
			for(Ghost ghost: g.getGame().getGhosts()){
				System.out.println(ghost.toString());
			}
			g.run();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}